package MapReduce.writableBean;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @Author lixinlei
 * @Date 2023/3/21 9:17
 */
public class TemperatureWritable implements WritableComparable<TemperatureWritable> {

    private int temperature;
    private int count;

    public int getTemperature() {
        return temperature;
    }

    public void setTemperature(int temperature) {
        this.temperature = temperature;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public int compareTo(TemperatureWritable o) {

        int thisTemp = this.getTemperature();
        int thatTemp = o.getTemperature();

        return thisTemp-thatTemp;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeInt(temperature);
        out.writeInt(count);
    }

    @Override
    public void readFields(DataInput in) throws IOException {

        this.temperature = in.readInt();
        this.count = in.readInt();

    }
}
